<template>
    <div class="template_container">
        <div class="btn_box">
            <el-button type="primary" @click.stop="toPrint">打印</el-button>
            <el-button @click.stop="goBack">返回</el-button>
        </div>
        <div class="assess_form swallow" ref="print_area">
            <div class="form_title">XXXX医疗机构</div>
            <div class="form_name">康复治疗记录单</div>
            <div class="form_patient_bar">
                <div v-for="(item, index) in patientStruct" :key="index" class="patient_info_item">
                    <div class="item_label">{{ item.label }}：</div>
                    <div class="item_value">{{ currentPatient[item.key] }}</div>
                </div>
            </div>
            <template v-if="infoList.length > 0">
                <div v-for="(item, index) in infoList" :key="index" class="record_item">
                    <div class="form_assess_title">
                        {{
                            item.doctorSignTime &&
                            moment(item.doctorSignTime).format("YYYY-MM-DD HH:mm:ss")
                        }}
                    </div>
                    <div class="form_assess_item">
                        {{ item.recoveredDesc }}
                    </div>
                    <div class="doctorSign">治疗师签名：{{ item.doctorSign }}</div>
                </div>
            </template>
            <el-empty v-else description="暂无数据"></el-empty>
        </div>
    </div>
</template>

<script>
import { getRecoveredList } from "@/api/therapistsSite/therapistsSite";
import Cookies from "js-cookie";
import { GENDET_LIST, getLabel } from "./enums";
import moment from "moment";
export default {
    name: "rehabilitationHistory",
    data() {
        return {
            formType: "edit",
            patientInfo: {},
            infoList: [],
        };
    },
    computed: {
        patientStruct() {
            return [
                {
                    label: "姓名",
                    key: "patientName",
                },
                {
                    label: "性别",
                    key: "genderName",
                },
                {
                    label: "年龄",
                    key: "age",
                },
                {
                    label: "科室",
                    key: "所在科室名称",
                },
                {
                    label: "床号",
                    key: "bedNum",
                },
                {
                    label: "住院号",
                    key: "admissionNum",
                },
            ];
        },
        currentPatient() {
            try {
                const info = JSON.parse(Cookies.get("currentPatient"));
                return info
                    ? {
                        ...info,
                        genderName: getLabel(info.gender, GENDET_LIST),
                    }
                    : {};
            } catch (res) {
                return {};
            }
        },
    },
    created() {
        this.getList();
    },
    mounted() { },
    methods: {
        moment,
        goBack() {
            this.$router.back();
        },
        toPrint() {
            this.$print(this.$refs.print_area);
        },
        getList() {
            getRecoveredList({
                patientId: this.currentPatient.patientId,
            }).then((res) => {
                this.infoList = res.content;
            });
        },
    },
};
</script>

<style lang="scss" scoped>
@import url("~@/views/assessSys/templates/style.scss");
@import url("~@/views/assessSys/components/style.scss");

.record_item {
    margin-top: 40px;

    .doctorSign {
        margin-top: 10px;
        text-align: right;
    }
}
</style>
